﻿import java.sql.*;
public class MySql2 {
    public static void main(String[] args) {
        Connection con;
        Statement sql;
        ResultSet rs;
        con = GetDBConnection.connectionDB("world","root","");
        if(con==null) {
            return;
        }
        try{
            sql = con.createStatement();
            rs = sql.executeQuery("SELECT * FROM country where Region='Middle East'");
            Long sum=0L;
            while (rs.next()){
                System.out.println(rs.getString(2)+"的人口为："+rs.getInt(7));
                sum=sum+rs.getInt(7);
            }
            System.out.println("中东国家的总人口为："+sum);
            con.close();
        }catch (SQLException e){
            System.out.println(e);
        }

    }
}